/*

Author   : chaos

FileName : str_constructor.cpp

Date     : 11/08/17 21:05:20

*/
#include <iostream>
#include <cstring>
using namespace std;

class String
{
    private:
        char* string;
        long len;
    public:
        String();
        String(const char * i_string);
        String(String & a_string);
        void show_string();
};

void String::show_string()
{
    cout << "string : " << string << " length : " << len << endl;
}

String::String()
{
    cout << "Default constructor is calld!" << endl;
}

String::String(const char * i_string):len (strlen(i_string))
{
    cout << "Type covert constructor is called !" << endl;
    string = new char(len + 1);
    strcpy(string,i_string);
}

String::String(String & a_string) : len (a_string.len)
{
    cout << "Copy constructor is called!" << endl;
    string = new char[len + 1];
    strcpy(string,a_string.string);
}

int main(int argc ,char *argv[])
{
    String A_String("My string");
    String B_String(A_String);
    String C_String;

    cout << "----------------------------" << endl;
    cout << "A_String : " << endl;
    A_String.show_string();

    cout << "B_String : " << endl;
    B_String.show_string();

    return 0;
}
